package com.edaoe.thread;

import com.edaoe.util.LuceneUtil;

/**
 * Created by Dull on 2017/4/1 0001.
 */
public class LuceneThread  implements Runnable{
    public static final int TYPE_ADD=1;
    public static final int TYPE_UPDATE=2;

    private long userId;
    private long articleId;
    private String text;
    private int type;

    /**
     * deleteAll构造器
     * @param userId
     */
    public LuceneThread(long userId){
        this.userId=userId;
    }

    /**
     * delete构造器
     * @param userId
     */
    public LuceneThread(long userId,long articleId){
        this.userId=userId;
        this.articleId=articleId;
    }

    /**
     * 增加和更新构造器
     */
    public LuceneThread(long userId,long articleId,String text,int type){
        this.userId=userId;
        this.articleId=articleId;
        this.text=text;
        this.type=type;
    }

    @Override
    public void run() {
        if (articleId==0){
            LuceneUtil.deleteAll(userId);
        }else{
            if (text==null){
                LuceneUtil.delete(userId,articleId);
            }else{
                if (type==TYPE_ADD){
                    LuceneUtil.add(userId,articleId,text);
                }else{
                    LuceneUtil.update(userId,articleId,text);
                }
            }
        }
    }
}
